package org.skill.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import javax.swing.SwingConstants;

import com.tool.image.ImageMixDeal;
import org.come.Frame.ZhuFrame;
import org.come.bean.LoginResult;
import org.come.until.AnalysisString;
import org.come.until.FormsManagement;
import org.skill.frame.SkillPromoteMainFrame;
import org.skill.panel.CopyOfSkillTYCPanel;

import com.tool.btn.MoBanBtn;
import com.tool.role.GetExp;
import com.tool.role.RoleData;

public class SkillTYCBtn extends MoBanBtn {
    /** 0切换(下拉按钮) 1兑换 2洗点 3模拟加点 4确认加点 */
    private int typeBtn;
    private CopyOfSkillTYCPanel skillTYCPanel;

    public SkillTYCBtn(String iconpath, int type, Color[] colors, String text, Font font, int typeBtn,
                       CopyOfSkillTYCPanel skillTYCPanel) {
        super(iconpath, type, colors);
        // TODO Auto-generated constructor stub
        setText(text);
        setFont(font);
        setHorizontalTextPosition(SwingConstants.CENTER);
        setVerticalTextPosition(SwingConstants.CENTER);
        this.typeBtn = typeBtn;
        this.skillTYCPanel = skillTYCPanel;
    }

    @Override
    public void chooseyes() {
    }

    @Override
    public void chooseno() {
    }

    @Override
    public void nochoose(MouseEvent e) {
        if (ImageMixDeal.userimg.getRoleShow().getBooth_id() != null) {
            ZhuFrame.getZhuJpanel().addPrompt2("摆摊状态不可以操作天演策！");
            return;
        }
        // TODO Auto-generated method stub
        if (typeBtn == 0) {
            if (skillTYCPanel.typeBtn == 1) {
                skillTYCPanel.getTYCselect().setVisible(true);
            }
        } else if (typeBtn == 1) {
            // 获取登录用户信息
            LoginResult loginResult = RoleData.getRoleData().getLoginResult();
            // 获取已兑换属性点
            int parseInt = loginResult.getExtraPointInt("T");
            // 获取人物经验
            BigDecimal experience = loginResult.getExperience();
            // 获取当前的天枢点
            int tsp = GetExp.getTSP(parseInt);
            // 获取当前的修为值
            int tsx = GetExp.getTSX(parseInt);
            // 获取当前等级兑换所需的经验值
            int tsExp = GetExp.getTSExp(tsp + 1);
            // 获取人物等级
            String lvl = AnalysisString.lvl(loginResult.getGrade());
            // 获取当前人物境界
            int realmNow = realmNow(loginResult.getGrade());
            // 获取当前人物可以兑换的最大天枢点
            int realmMaxTSP = realmMaxTSP(realmNow);
            // 获取当前人物境界名称
            String raceConfirm = raceConfirm(loginResult.getRace_id(), realmNow);
            SkillPromoteMainFrame.getSkillPromoteMainFrame().getSkillPromoteMainPanel()
                    .panelGetData(experience, tsx, tsExp, lvl, raceConfirm, tsp, realmMaxTSP);
            FormsManagement.showForm(83);
        } else if (typeBtn == 2) {
            skillTYCPanel.washPoint();
        } else if (typeBtn == 3) {
            skillTYCPanel.changeBtnPanel(skillTYCPanel.typeBtn == 0 ? 1 : 0);
        } else if (typeBtn == 4) {
            if (skillTYCPanel.typeBtn == 0) {
                skillTYCPanel.addPoint();
            }
        }
    }

    /** 判断人物现在第几境界 第一境界:315 第二境界:335 第三境界:417 第四境界:437 */
    public static int realmNow(int level) {
        if (level >= 437) {
            return 4;
        } else if (level >= 417) {
            return 3;
        } else if (level >= 335) {
            return 2;
        } else if (level >= 315) {
            return 1;
        }
        return 0;
    }

    /** 10001 人 10002 魔 10003 仙 10004 鬼 判断各个职业所对应的境界名称 */
    public static String raceConfirm(BigDecimal raceId, int realmNow) {
        switch (raceId.toString()) {
            case "10001":
                return realmConfirm("旋照期|开光期|融合期|灵寂期", realmNow);
            case "10002":
                return realmConfirm("魔光期|凝元期|结丹期|离婴期", realmNow);
            case "10004":
                return realmConfirm("炼魂期|混沌期|空冥期|神游期", realmNow);
            case "10003":
                return realmConfirm("地仙期|天仙期|玄仙期|金仙期", realmNow);
            default:
                return null;
        }
    }

    /** 判断当前境界名称 */
    public static String realmConfirm(String raceNmae, int realmNow) {
        if (realmNow <= 0) {
            return null;
        }
        return raceNmae.split("\\|")[realmNow - 1];
    }

    /** 获取当前境界可以兑换的最大天枢点 */
    public static int realmMaxTSP(int realm) {
        switch (realm) {
            case 1:
                return 15;
            case 2:
                return 25;
            case 3:
                return 40;
            case 4:
                return 60;
            default:
                return 0;
        }
    }

}
